package cn.edu.njust.epms.dao;

import cn.edu.njust.epms.entity.ATRecord;
import cn.edu.njust.epms.entity.uItem;
import cn.edu.njust.epms.common.R;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ItemDao {
    @Select("<script>"+
            "SELECT * FROM uitem inner join udetails on udetails.uId=uitem.uId and udetails.isSelf=1"+
            "<where>"+
            "   <if test='r.name != null and r.name.length > 0'>"+
            "       AND name like #{r.name}"+
            "   </if>"+
            "   <if test='r.oState != null'>"+
            "       AND oState = #{r.oState}"+
            "   </if>"+
            "   <if test='r.uId != null'>"+
            "       AND udetails.uId = #{r.uId}"+
            "   </if>"+
            "   <if test='r.pid != null and r.pid.length > 0'>"+
            "       AND udetails.pid like #{r.pid}"+
            "   </if>"+
            "   <if test='r.date1 != null and r.date2 != null'>"+
            "       AND oTime between #{r.date1} and #{r.date2}"+
            "   </if>"+
            "</where>"+
            "</script>")
    @Results({
            @Result(column = "oId",property = "oId"),
            @Result(column = "oTime",property = "oTime"),
            @Result(column = "uId",property = "uId"),
            @Result(column = "req",property = "req"),
            @Result(column = "oState",property = "oState"),
            @Result(column = "uNote",property = "uNote"),
            @Result(column = "oNote",property = "oNote"),
            @Result(column = "oTime",property = "oTime"),
            @Result(column = "pid",property = "ud.pid"),
            @Result(column = "name",property = "ud.name"),
            @Result(column = "addr",property = "ud.addr"),
            @Result(column = "phone",property = "ud.phone")

    })
    public List<uItem> selectByCondition(@Param("r") R r);

    @Insert("insert into uItem (uId,req,oState,uNote,oTime) values(#{uId},#{req},#{oState},#{uNote},#{oTime})")
    public boolean add(uItem i);

    @Update("update uitem set oState=#{oState},oNote=#{oNote} where oId = #{oId}")
    public boolean update(uItem i);

    @Select("select * from uitem where oId = #{oId}")
    public uItem selectById(Integer oId);

    @Delete("delete from uitem where oId=#{oId}")
    public boolean deleteOrder(Integer oId);

    @Delete("delete from uitem where oId=#{oId}")
    public Boolean deleteItemApp(uItem i);
}
